package mvc.model.service.impl;

import mvc.model.dao.AddrDao;
import mvc.model.dao.impl.AddrDaoImpl;
import mvc.model.pojos.AddressBean;
import mvc.model.service.AddressService;

import java.util.List;

public class AddressServiceImpl implements AddressService {
    private final static AddrDao addrDao;
    static {
        addrDao = new AddrDaoImpl();
    }
    @Override
    public void addAddress(AddressBean addressBean) {
        if (addressBean.getIsdefault() == 1) {
            AddressBean one = addrDao.selectOne(1, addressBean.getUid());
            if (one != null) {
                one.setIsdefault(0);
                addrDao.upAddress(one, one.getAnumber());
            }
        }
        addrDao.addAddress(addressBean);

    }

    @Override
    public List<AddressBean> select(int uid, int flag) {
        return addrDao.select(uid, flag);
    }

    @Override
    public void deletAddr(int anumber) {
        AddressBean addressBean = addrDao.queryOne(anumber);
        addressBean.setFlag(0);
        addrDao.upAddress(addressBean, anumber);

    }

}
